package com.vhall.component.controller.interactive;

import com.vhall.component.controller.interactive.facade.QuestionConsoleFacade;
import com.vhall.component.entity.interactive.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.constant.ConstStr;
import com.vhall.component.service.interactive.QuestionConsoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021-06-11 16:36
 */
@VhallComponent
public class QuestionConsoleController implements QuestionConsoleFacade {

    @Autowired
    private QuestionConsoleService questionConsoleService;

    @TokenAuth
    @Override
    public QuestionPage<QuestionConsoleLinkRoomListRspVO> linkRoomList(QuestionConsoleLinkRoomListReqVO reqVO) {
        if (reqVO.getPage() == null) {
            reqVO.setPage(1);
        }
        if (reqVO.getPageSize() == null) {
            reqVO.setPageSize(10);
        }
        return questionConsoleService.linkRoomList(reqVO);
    }

    @TokenAuth
    @Override
    public QuestionConsoleCreateRspVO create(QuestionConsoleCreateReqVO reqVO) {
        return questionConsoleService.create(reqVO);
    }

    @TokenAuth
    @Override
    public QuestionPage<QuestionConsoleListRspVO> list(QuestionConsoleListReqVO reqVO) {
        if (reqVO.getPage() == null) {
            reqVO.setPage(1);
        }
        if (reqVO.getPageSize() == null) {
            reqVO.setPageSize(20);
        }
        return questionConsoleService.list(reqVO);
    }

    @TokenAuth
    @Override
    public List<String> delete(QuestionConsoleDeleteReqVO reqVO) {
        return questionConsoleService.delete(reqVO);
    }

    @TokenAuth
    @Override
    public String publish(QuestionConsolePublishReqVO reqVO) {
        return questionConsoleService.publish(reqVO);
    }

    @TokenAuth
    @Override
    public QuestionConsoleCreateRspVO update(QuestionConsoleUpdateReqVO reqVO) {
        return questionConsoleService.update(reqVO);
    }


    @TokenAuth
    @Override
    public QuestionLogPage<QuestionConsoleLogRspVO> getQuestionLog(QuestionConsoleLogReqVO req) {
        if (req.getPage() == null || "0".equals(String.valueOf(req.getPage()))) {
            req.setPage(1);
        }
        if (req.getPageSize() == null) {
            req.setPageSize(10);
        }
        if (StringUtils.isNotBlank(req.getEndTime())) {
            String endTime = req.getEndTime();
            if (endTime.contains(ConstStr.TIME_ZERO)) {
                endTime = endTime.replace(ConstStr.TIME_ZERO, ConstStr.TIME_FULL);
            } else {
                endTime = endTime + " " + ConstStr.TIME_FULL;
            }
            req.setEndTime(endTime);
        }
        return questionConsoleService.getQuestionLog(req);
    }
}
